﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication2
{
    public partial class Register : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        //取消
        protected void tbRegister_Click(object sender, EventArgs e)
        {
            Response.Redirect("Login.aspx");
        }
        //注册
        protected void tbLogin_Click(object sender, EventArgs e)
        {
            var uid = tbusername.Text.Trim();
            var pwd = tbpassword.Text.Trim();
            var repwd = tbrepassword.Text.Trim();

            var sql = string.Format("select * from Users where Username='{0}'", uid);
            var dt = DbHelp.GetData(sql);

            if (dt.Rows.Count == 1)
            {
                Response.Write("该用户名已存在");
            }
            else
            {
                if (pwd != repwd)
                {
                    Response.Write("两次输入的密码不一致");
                }
                else
                {
                    var sql2 = string.Format("insert into Users(Username,Password) values('{0}','{1}')", uid, pwd);
                    DbHelp.AddOrUpdate(sql2);
                    Response.Write("注册成功！");
                    
                }
            }
        }
    }
}